const express = require('express')
const path = require('path')
const bodyParser = require('body-parser');
const cors = require('cors')
const user  = require(path.join(__dirname,'./routes/user'))
const familymanagement = require(path.join(__dirname,'./routes/familyManagement'))
const oldermanmanagement = require(path.join(__dirname,'./routes/oldermanmanagement'))
const healthmanagement = require(path.join(__dirname,'./routes/healthmanagement'))
const consultmanagement = require(path.join(__dirname,'./routes/consultmanagement'))
const visitmanagement = require(path.join(__dirname,'./routes/visitmanagement'))
const caremessagemanagement = require(path.join(__dirname,'./routes/caremessagemanagement'))
const caredailymanagement = require(path.join(__dirname,'./routes/caredailymanagement'))
const bedmessagemanagement = require(path.join(__dirname,'./routes/bedmessagemanagement'))
const usermanagement = require(path.join(__dirname,'./routes/usermanagement'))
const announcements = require(path.join(__dirname,'./routes/announcements'))


// 1.创建app
const app = express()

// 解析 application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// 解析 application/json
app.use(bodyParser.json());

app.use(cors());

// app.use('/public/',express.static(path.join(__dirname,'./public/')))
// app.use('/node_modules/',express.static(path.join(__dirname,'./node_modules/')))

//设置跨域请求
app.all('*', function (req, res, next) {
	res.header("Access-Control-Allow-Origin", "*");
	res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
	res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
	res.header("X-Powered-By", ' 3.2.1')
	res.header("Content-Type", "application/json;charset=utf-8");
	next();
});

app.use("/api/user",user);
app.use("/api/familymanagement",familymanagement)
app.use("/api/oldermanmanagement",oldermanmanagement)
app.use("/api/healthmanagement",healthmanagement)
app.use("/api/consultmanagement",consultmanagement)
app.use("/api/visitmanagement",visitmanagement)
app.use("/api/caremessagemanagement",caremessagemanagement)
app.use("/api/caredailymanagement",caredailymanagement)
app.use("/api/bedmessagemanagement",bedmessagemanagement)
app.use("/api/usermanagement",usermanagement)
app.use("/api/announcements",announcements)


app.listen(13520,function(){
  console.log('server is running');
})